package by.semerikov.statictic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import by.semerikov.parts.Log;

public class StaticticByPartDay {

	public static String[] parts = { "morning", "afternoon", "evening", "night" };

	private List<Log> list = new ArrayList<>();

	public StaticticByPartDay(List<Log> list) {
		this.setList(list);
	}

	public Map<String, Integer> getStaticticByPartDay() {
		Map<String, Integer> result = new HashMap<String, Integer>();
		
			for (int j = 0; j < list.size(); j++) {
				Integer count = result.get(getPart(list.get(j).getDate().getHour()));
				if ( count == null )
				{
					count = 0;
				}
				count++;
				result.put(getPart(list.get(j).getDate().getHour()) , count);
			}
			
		
		return result;
	}

	private String getPart(Integer hour) {
		if (hour > 6 && hour < 10) {
			return "morning";
		} else if (hour >= 10 && hour < 16) {
			return "afternoon";
		} else if (hour >= 16 && hour < 23) {
			return "evening";
		} else {
			return "night";
		}
	}

	public List<Log> getList() {
		return list;
	}

	public void setList(List<Log> list) {
		this.list = list;
	}

}
